package org.example.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.springcloud.entities.Payment;
import org.example.springcloud.service.PaymentService;
import org.example.springcloud.utils.ResultVOUtil;
import org.example.springcloud.vo.ResultVO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * (Payment)表控制层
 *
 * @author makejava
 * @since 2020-03-06 14:22:26
 */
@Slf4j
@RestController
@RequestMapping("payment")
public class PaymentController {
    /**
     * 服务对象
     */
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("get/{id}")
    public ResultVO<?> selectOne(@PathVariable("id") Long id) {
        Payment payment = this.paymentService.queryById(id);
        return  ResultVOUtil.success(payment,serverPort);
    }

    @PostMapping("create")
    public ResultVO<?> create(@RequestBody Payment payment) {
        Payment insert = this.paymentService.insert(payment);
        return  ResultVOUtil.success(insert,serverPort);
    }
}